
package fr.enseirbmatmeca.apms.tapestry.pages.student;

import java.util.List;

import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.Request;

import fr.enseirbmatmeca.apms.spring.security.ConstantRoleUserService;
import fr.enseirbmatmeca.apms.spring.security.ProjectRole;
import fr.enseirbmatmeca.apms.tapestry.pages.Index;
import fr.enseirbmatmeca.apms.tapestry.pages.Security;

public class DetailProject extends Security {


	Object onActivate() {
		String role = getRole();
		
		String idProject = (String) request.getParameter("id");
		String idGroup = (String) request.getAttribute("group");

		if (idProject==null){
			return Index.class;
		}else if (idGroup==null){
			return Index.class;
		}
		
		List<ProjectRole> listProjectRole = getListProjectRole(idProject);

		if (role==null)
			return Index.class;	
		else if (role.equals(ConstantRoleUserService.ADMINISTRATOR)) 
			return true;
		else if (role.equals(ConstantRoleUserService.USER)){
			for (ProjectRole projectRole : listProjectRole)
				if (idGroup.equals(projectRole.getProjectGroupId()) && projectRole.getAuthority().equals(ProjectRole.AUTHORITY_STUDENT))
					return true;
			return Index.class;
		}else 
			return Index.class; 

	} 
}
